<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
<h1>文件上传</h1>
<!--
<input id="inputId" type="file" name="file"/>
<input type="button" value="七牛上传" onclick="uploadImg()" />
 -->
<!--  -->
 <form method="post" action="qiniu" enctype="multipart/form-data">
	<input type="hidden" name="uid" value="2" />
    <input type="file" name="file"><br>
    <input type="submit" value="提交">
</form>

 <!-- 
<form method="post" action="/manyimg" enctype="multipart/form-data">
	<input type="hidden" name="hid" value="1" />
    <input type="file" name="file"><br>
    <input type="file" name="file"><br>
    <input type="file" name="file"><br>
    <input type="submit" value="提交">
</form>
-->
<script type="text/javascript">
         
    /**
     * 上传图片
     */
    function uploadImg() {
        /**
         * formData在jquey中使用需要设置：
         * processData: false, // 告诉jQuery不要去处理发送的数据
         * contentType: false // 告诉jQuery不要去设置Content-Type请求头
         * @type {null}
         */
        var fd = new FormData();
        // 第一个参数为controller 接收的参数名称 , input的id
        fd.append("file", document.getElementById("inputId").files[0]);
        

        $.ajax({
            url: "http://localhost:8080/qiniu",
            type: "post",
            processData: false,
            contentType: false,
            data:{"uid":2,"file":fd},
            success: function (res) {
                console.log(res);
            },
            dataType: "json"
        });
    }
</script>
</body>
</html>